package com.zdb.demo.spark.sql.parser;

import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CommonTokenStream;
import org.apache.spark.sql.catalyst.parser.SqlBaseLexer;
import org.apache.spark.sql.catalyst.parser.SqlBaseParser;

public class ParserDriverTest {

    public static void main(String[] args) {
        String sql = "select * from student where age>18";

        SqlBaseLexer lexer = new SqlBaseLexer(new ANTLRInputStream(sql.toUpperCase()));

        SqlBaseParser parser = new SqlBaseParser(new CommonTokenStream(lexer));

        SqlBaseParser.SingleStatementContext singleStatementContext = parser.singleStatement();
        System.out.println(singleStatementContext.toStringTree());

        MyVisitor visitor = new MyVisitor();

        visitor.visitSingleStatement(parser.singleStatement());
    }
}
